//
//  SQAlarmRecordViewController.m
//  energy
//
//  Created by 苏青 on 2021/9/29.
//

#import "SQAlarmRecordViewController.h"
/**发布应急响应*/
#import "SQAddReleaseViewController.h"

//༥༤༽ཀབཀྲ་ཤིས་བདེ་ལེགས།
#import "SQAlarmRecordModel.h"
#import "SQUpdateEmergencyModel.h"


@interface SQAlarmRecordViewController ()<BaseTableVCInterface>

@end

@implementation SQAlarmRecordViewController

- (void)viewDidLoad {
    self.tableViewInterface = self;
    [super viewDidLoad];
    self.navigationItem.title = @"报警记录";
    [self getAlarmRecordData];
    
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getConfirmData) name:@"confirm" object:nil];
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self getAlarmRecordData];
    }];
    LC_WEAK_SELF
    self.cellTitleIndex = ^(NSString * str, int key) {
        SQAlarmRecordModelData * dataModel = weakSelf.dataSouece[key];
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"处理应急响应"
                                                                           message:nil
                                                                    preferredStyle:UIAlertControllerStyleActionSheet];
        UIAlertAction* releaseAction = [UIAlertAction actionWithTitle:@"发布应急响应" style:UIAlertActionStyleDefault
                                                              handler:^(UIAlertAction * action) {
                                                                  //响应事件
            [SQUpdateEmergencyModel getDataWithParams:@{@"apr_id":dataModel.apr_id,@"apr_state":@"1"} WithCallBack:^(SQUpdateEmergencyModel * data) {
                SQAddReleaseViewController * addReleaseVC = SQAddReleaseViewController.new;
                addReleaseVC.apr_alarm_person = dataModel.apr_alarm_person;
                [weakSelf pushVC:addReleaseVC];
            }];
            
        }];
       
        
        UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"误报" style:UIAlertActionStyleDefault
                                                              handler:^(UIAlertAction * action) {
                                                                  //响应事件
            [SQUpdateEmergencyModel getDataWithParams:@{@"apr_id":dataModel.apr_id,@"apr_state":@"2"} WithCallBack:^(SQUpdateEmergencyModel * data) {
                
            }];
            
        }];
        
        UIAlertAction* accidentAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel
                                                              handler:^(UIAlertAction * action) {
                                                                  //响应事件
            NSLog(@"action = %@", action);
        }];
        [alert addAction:releaseAction];
        [alert addAction:cancelAction];
        [alert addAction:accidentAction];
        [weakSelf presentViewController:alert animated:YES completion:nil];
        
    };
    
}

-(void)getAlarmRecordData{
    [SQAlarmRecordModel getDataWithParams:@{@"apr_enterprise":MEnterpriseId} WithCallBack:^(SQAlarmRecordModel * data) {
        [self detailModelwithArr:data.data withCallBack:nil];
        [self reloadTableView];
        
    }];
}

-(BaseModel *)modelForCell:(NSIndexPath *)indexPath{
    return self.dataSouece[indexPath.row];
}



-(NSInteger)rowsCount:(NSInteger)section{
    return self.dataSouece.count;
}


- (NSArray<NSArray<NSString *> *> *)classArr{
    return @[@[@"SQAlarmRecordTableViewCell"]];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
